<?php

namespace Acme\CommonBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

use Acme\UserBundle\Entity\CmUser;

/**
 * @Route("/teacher")
 */
class TeacherController extends Controller
{
	/**
	 * @Route("/js_teacher_generator/{userStatus}/{flag}", defaults={"userStatus" = "", "flag" = ""}, name="AcmeCommonBundle_JsTeacherGenerator")
	 * @Template()
	 */
	public function jsTeacherGeneratorAction($userStatus, $flag) {
		if (isset($userStatus) && $userStatus != '') {
			$condition['userStatus'] = array_search($userStatus, $this->container->getParameter('userStatusEn'));
		}
		if (isset($flag) && $flag != '') {
			$condition['flag'] = array_search($flag, $this->container->getParameter('flagEn'));
		}
		
		$condition['userCategory'] = array_search('teacher', $this->container->getParameter('userCategoryEn'));	
		
		$em = $this->getDoctrine()->getEntityManager();
		$temp_data = $em->getRepository('AcmeUserBundle:CmUser')->findUserByConditionJoined($condition);
		foreach ($temp_data as $v) {
			if ($v instanceof CmUser) {
				$data[] = array('id' => $v->getId(), 'username' => $v->getUsername(), 'name' => $v->getUserInfo()->getName(), 'university' => $v->getUserInfo()->getUniversity());
			}
		}
		
		//echo "<pre>";
		//print_r($data);
		//return ;
		
		return array('data' => json_encode($data));
	}
}
